package com.haier.npt.filter.authorization;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.haier.npt.security.domain.SysPermission;


/**
 * @Description:
 * @author: lixu
 * @date:   2018年7月12日 下午9:19:11   
 */
public class UserTokenAuthorizationFilter extends AbstractAuthorizationFilter {

    /**
     * 登录成功返回权限信息
     */
    @Override
    public List<SysPermission> onAuthorization(HttpServletRequest request, HttpServletResponse response) {
        Long userId = super.getUserid();
        return this.listPermissionByUserId(userId);
    }


    /**
     * 查询用户当前的权限
     *
     * @param userId   当前用户id
     * @return
     */
    private List<SysPermission> listPermissionByUserId(Long userId) {
          return permissionSupport.listPermissionByUserId( userId, super.getToken());
    }

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 3;
    }

}
